package com.ruoyi.mall.product.service;

import com.ruoyi.mall.product.domain.entity.PmsAttr;
import com.ruoyi.mall.product.domain.entity.PmsAttrGroup;
import com.ruoyi.mall.product.domain.service.IPmsAttrGroupService;
import com.ruoyi.mall.product.domain.vo.PmsAttrGroupAttrsVo;
import com.ruoyi.mall.product.domain.vo.PmsAttrGroupVo;
import com.ruoyi.mall.product.domain.vo.TreeSelect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: zqs-mall
 * @description:
 * @author: Mr.Zhang
 * @create: 2022-06-07 23:10
 **/
@Service
public class PmsAttrGroupAppService {
    @Autowired
    private IPmsAttrGroupService pmsAttrGroupService;

    @Autowired
    private PmsCategoryAppService pmsCategoryAppService;

    /**
     * 查询属性分组
     *
     * @param id 属性分组主键
     * @return 属性分组
     */
    public PmsAttrGroup selectPmsAttrGroupById(Long id) {

        PmsAttrGroup pmsAttrGroup = pmsAttrGroupService.selectPmsAttrGroupById(id);
        Long categoryId = pmsAttrGroup.getCategoryId();
        //查找出某个三级分类下的完整数据
        Long[] path = pmsCategoryAppService.findCategoryPath(categoryId);
        pmsAttrGroup.setValues(path);

        return pmsAttrGroup;
    }

    /**
     * 查询属性分组列表
     *
     * @return
     */
    public List<PmsAttrGroup> selectPmsAttrGroupList(PmsAttrGroup pmsAttrGroup) {
        return pmsAttrGroupService.selectPmsAttrGroupList(pmsAttrGroup);
    }

    /**
     * 新增属性分组
     *
     * @param pmsAttrGroup 属性分组
     * @return 结果
     */
    public int insertPmsAttrGroup(PmsAttrGroup pmsAttrGroup) {
        return pmsAttrGroupService.insertPmsAttrGroup(pmsAttrGroup);
    }

    /**
     * 修改属性分组
     *
     * @param pmsAttrGroup 属性分组
     * @return 结果
     */
    public int updatePmsAttrGroup(PmsAttrGroup pmsAttrGroup) {
        return pmsAttrGroupService.updatePmsAttrGroup(pmsAttrGroup);
    }

    /**
     * 批量删除属性分组
     *
     * @param ids 需要删除的属性分组主键
     * @return 结果
     */
    public int deletePmsAttrGroupByIds(Long[] ids) {
        return pmsAttrGroupService.deletePmsAttrGroupByIds(ids);
    }

    /**
     * 删除属性分组信息
     *
     * @param id 属性分组主键
     * @return 结果
     */
    public int deletePmsAttrGroupById(Long id) {
        return pmsAttrGroupService.deletePmsAttrGroupById(id);
    }

    /**
     * 查询分组关联关系
     *
     * @param attrGroupId
     * @return
     */
    public List<PmsAttr> selectPmsAttrGroupRelation(Long attrGroupId) {
        return pmsAttrGroupService.selectPmsAttrGroupRelation(attrGroupId);
    }

    /**
     * 删除分组关联关系
     * @param pmsAttrGroupVo
     * @return
     */
    public int deletePmsAttrGroupRelation(PmsAttrGroupVo[] pmsAttrGroupVo) {
        return pmsAttrGroupService.deletePmsAttrGroupRelation(pmsAttrGroupVo);
    }

    /**
     * 获取当前分组没有关联的
     * @param attrGroupId
     * @return
     */
    public List<PmsAttr> selectPmsAttrGroupRelationNot(PmsAttr pmsAttr,Long attrGroupId) {
        return pmsAttrGroupService.selectPmsAttrGroupRelationNot(pmsAttr,attrGroupId);
    }

    public int insertPmsAttrGroupRelation(List<PmsAttrGroupVo> pmsAttrGroupVos) {
        return pmsAttrGroupService.insertPmsAttrGroupRelation(pmsAttrGroupVos);
    }

    /**
     * 查询分类下的分组信息 和分组信息所关联的属性信息
     * @param categoryId
     * @return
     */
    public List<PmsAttrGroupAttrsVo> listWithAttr(Long categoryId) {
        return pmsAttrGroupService.listWithAttr(categoryId);
    }
}
